package com.gxm.算法;

import org.junit.Test;

public class Sort {

    @Test
    public void test() {
        int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

    }

    /**
     * 冒泡排序
     *
     * @param array
     */
    @Test
    public void bubbleSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }

    /**
     * 选择排序
     */
    @Test
    public void selectSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            int min = i;
            for (int j = i + 1; j < array.length; j++) {
                if (array[j] < array[min]) {
                    min = j;
                }
            }
            if (min != i) {
                int temp = array[i];
                array[i] = array[min];
                array[min] = temp;
            }
        }
    }

    /**
     * 二分查找
     */
    @Test
    public void binarySearch(int[] array, int key) {
        int low = 0;
    }
}
